<?php
namespace App\Providers;

use App\Manager\StorageManager;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;

use Overtrue\LaravelUEditor\UEditorServiceProvider as OldUEditorServiceProvider;

/**
 * Class UEditorServiceProvider.
 */
class UEditorServiceProvider extends OldUEditorServiceProvider
{
    /**
     * Register any application services.
     */
    public function register()
    {
        $this->app->singleton('ueditor.storage', function ($app) {
            return new StorageManager(Storage::disk(config('ueditor.disk', 'public')));
        });
    }

    /**
     * Register routes.
     *
     * @param $router
     */
    protected function registerRoute($router)
    {
        if (!$this->app->routesAreCached()) {
            $router->group(array_merge(['namespace' => __NAMESPACE__], config('ueditor.route.options', [])), function ($router) {
                $router->any(config('ueditor.route.name', '/ueditor/server'), 'UEditorController@serve');
            });
        }
    }
}
